package com.example.a66666.yuejian.Adapter;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.a66666.yuejian.Activity.GameDetailActivity;
import com.example.a66666.yuejian.Activity.MasterDetailActivity;
import com.example.a66666.yuejian.Bean.ActivityBean;
import com.example.a66666.yuejian.Bean.MasterBean;
import com.example.a66666.yuejian.MyViewHolder.ItemViewHolder;
import com.example.a66666.yuejian.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by 66666 on 2018/9/29.
 */

public class MasterAdapter extends RecyclerView.Adapter {

    private List<MasterBean> masterBeanList;
    public void setData(List<MasterBean> list){
        masterBeanList=list;
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater=LayoutInflater.from(parent.getContext());
        View itemView=inflater.inflate(R.layout.recyclerview_item,parent,false);
        ItemViewHolder viewHolder=new ItemViewHolder(itemView);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final ItemViewHolder viewHolder=(ItemViewHolder)holder;
        MasterBean masterBean=masterBeanList.get(position);
        String name=masterBean.getMname();
        String phone=masterBean.getMphone();
        String pic=masterBean.getMpic();
        viewHolder.name.setText("大师姓名："+name);
        viewHolder.time.setText("大师电话："+phone);
        Picasso.with(viewHolder.imageView.getContext()).load("http://10.0.2.2/yuejian/public/static/masterpic/"+pic).into(viewHolder.imageView);

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int pos=viewHolder.getLayoutPosition();
                Intent intent=new Intent(v.getContext(), MasterDetailActivity.class);
                intent.putExtra("masterID",masterBeanList.get(pos).getMid());
                v.getContext().startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        if(masterBeanList!=null)
            return masterBeanList.size();
        else
            return 0;
    }
}
